#include <stdio.h>
#include <stdlib.h>
#include "list.h"


static void __list_add(list_t  *new_lst, list_t *prev, list_t *next) {
        next->prev = new_lst;
        new_lst->next = next;
        new_lst->prev = prev;
        prev->next = new_lst;
}

static void __list_del(list_t * prev, list_t * next  ) {
        next->prev = prev;
        prev->next = next;
}

void initList(list_t *head) {
    head->next = head;
    head->prev = head;
}

int list_isEmpty(list_t *head){
        return head->next == head;
}

void list_add(list_t *new_lst, list_t *head){
 __list_add(new_lst, head, head->next);
}

void list_add_tail(list_t *new_lst, list_t *head){
        __list_add(new_lst, head->prev, head);
}

void list_del(list_t * entry) {
        __list_del(entry->prev,entry->next);
        entry->next = entry;
        entry->prev = entry;
}

